cd "C:\Users\s12144\Dropbox\corona"
*import excel "C:\Users\s12144\Dropbox\corona\20200704hospital.xlsx", sheet("hospital") firstrow clear
*save "20200708FINAL.dta", replace
use "20200821FINAL.dta", clear
* Create country dummies
encode country, gen(id)
* Set panel
xtset id date
* For Sweden we interpolate intensive care patients between March 6-March 18 assuming exponential growth
gen logint=log(intensive_care)
reg logint date if date>td(5mar2020) & date<td(19mar2020) & country=="Sweden"
predict tmp
replace intensive_care=exp(tmp) if date>td(5mar2020) & date<td(19mar2020) & country=="Sweden"
drop tmp
*** Number of inhabitants for each country
gen inhabitants=0
replace inhabitants=5367580 if country=="Norway"
replace inhabitants=10327589 if country=="Sweden"
replace inhabitants=5827463 if country=="Denmark"
*** Normalize data on hospitalization and ICU for Denmark, Sweden and Norway to data per inhabitant
gen hospitalizedperinh=hospitalized/inh*1000000
gen ICUperinh=intensive_care/inh*1000000
gen deathsperinh=total_d/inh*1000000
* Create a dummy for Norway and Denmark
gen dummydenmark=0
replace dummydenmark=1 if country=="Denmark"
label var dummydenmark "Denmark Fixed Effect"
gen dummynorway=0
replace dummynorway=1 if country=="Norway"
label var dummynorway "Norway Fixed Effect"
* Now calculate the difference for each variable between Denmark/Norway and Sweden
sort date id
foreach var of varlist hospitalizedperinh ICUperinh deathsperinh {
by date: gen diffD`var'=`var'[1]-`var'[_N]
by date: gen diffN`var'=`var'[2]-`var'[_N]
}
label var date "date"
label var diffDh "Hospitalizations DK-SW"
label var diffDI "Denmark-Sweden"
label var diffDd "Deaths DK-SW"
label var diffNh "Hospitalizations NO-SW"
label var diffNI "Norway-Sweden"
label var diffNd "Deaths NO-SW"
* Set number of days that will be used for one dummy
local days=7
sum date
local maxdate=td(30jun2020)
local mindate=td(05mar2020)
* I is the number of x days-period between lockdown and the end of the sample
local I=ceil((`maxdate'-`mindate')/`days')
* Now create a dummy for each x-day period after the lockdown
forval i=1/`I' {
gen after`i'=0
gen tmp=td(05mar2020)+(`i'-1)*`days'
gen tmp2=td(05mar2020)+`i'*`days'
replace after`i'=1 if date>=tmp & date<tmp2
drop tmp*
}
* Interact the periods with the dummies for Norway and Denmark
forval i=1/`I' {
gen intdenmark`i'=after`i'*dummydenmark
gen intnorway`i'=after`i'*dummynorway
}
* Now we create an event-study
* Drop the variables for the second period which will serve as the omitted period in the regressions
drop after2 intdenmark2 intnorway2
gen sample=date>td(04mar2020) & date<td(01jul2020)
xtset id date
* Now run regressions
foreach var of varlist ICUperinh deathsperinh {
* Run the event-study regression for each variable of interest
reg `var' after* intd* intn* dummyd dummyn if sample, vce(rob)
* Store the coefficients, the dates to which they belong and their 95-percent confidence interval in a matrix
mat coefficients=[_b[intdenmark1], _b[intdenmark1]-2*_se[intdenmark1], _b[intdenmark1]+2*_se[intdenmark1], _b[intnorway1], _b[intnorway1]-2*_se[intnorway1], _b[intnorway1]+2*_se[intnorway1] , td(08mar2020)]
mat coefficients=coefficients \ [0,0,0,0,0,0,td(15mar2020)]
forval i=3/`I' {
mat coefficients=coefficients \ [_b[intdenmark`i'],_b[intdenmark`i']-2*_se[intdenmark`i'],_b[intdenmark`i']+2*_se[intdenmark`i'],_b[intnorway`i'],_b[intnorway`i']-2* _se[intnorway`i'], _b[intnorway`i']+2* _se[intnorway`i'] , td(08mar2020)+7*(`i'-1)]
}
* Give names to the columns
matrix colnames coefficients= Denmark Denmark_lb Denmark_ub Norway Norway_lb Norway_ub date
* Preserve and clear the data
preserve
clear
* Use the matrix of coefficients as the data
svmat coefficients, names(col)
save coeffients`var', replace
* Save the mindate and maxdate as locals in Stata format
local mindate=td(08mar2020)
local maxdate=td(28jun2020)
local vertical=td(11mar2020)
local vertical2=td(20apr2020)
twoway (line Denmark date, lcolor(red)) (line Norway date , lcolor(black)) (rcap Denmark_ub Denmark_lb date , lcolor(red)) (rcap Norway_ub Norway_lb date , lcolor(black))/*
*/, legend(order(1 "Denmark" 2 "Norway")) xtitle("") ytitle("") xline(`vertical', lcolor(cyan)) xline(`vertical2', lcolor(cyan) lpattern(dash)) yline(0, lcolor(black)) graphregion(margin(2 5 2 2)) legend(size(large)) ylabel(,labsize(large))/*
*/ xlabel(`mindate'(14)`maxdate', labsize(large) format(%tdddMon))
graph export "paper\figure`var'.png", replace
local maxdate=td(7apr2020)
twoway (line Denmark date if date<`maxdate', lcolor(red)) (line Norway date if date<`maxdate', lcolor(black)) (rcap Denmark_ub Denmark_lb date if date<`maxdate' , lcolor(red)) (rcap Norway_ub Norway_lb date  if date<`maxdate', lcolor(black))/*
*/, legend(order(1 "Denmark" 2 "Norway")) xtitle("") ytitle("") xline(`vertical', lcolor(cyan)) yline(0, lcolor(black)) graphregion(margin(2 5 2 2)) legend(size(large)) ylabel(,labsize(large))/*
*/ xlabel(`mindate'(7)`maxdate', labsize(large) format(%tdddMon)) 
graph export "paper\figure`var'zoom.png", replace
restore
}
*** Now we find the difference between the actual peak and the counterfactual peak
foreach var of varlist ICUperinh deathsperinh {
* Find the actual maximum
bys country: egen max`var'=max(`var')
* Create a dummy which equals 1 on the date the variable attains its maximum
gen tmp=`var'==max`var'
gen tmp2=date*tmp
bys country: egen maxdate`var'=max(tmp2)
format maxdate`var' %d
drop tmp*
* Now generate the counterfactual values for Norway and Denmark
qui reg `var' after* intd* intn* dummyd dummyn if sample, vce(rob)
gen cf`var'=_b[_cons]+dummydenmark*_b[dummydenmark]+_b[dummynorway]*dummynorway+_b[after1]*after1+_b[after3]*after3+_b[after4]*after4+_b[after5]*after5+/*
*/_b[after6]*after6+_b[after7]*after7+_b[after8]*after8+_b[after9]*after9+_b[after10]*after10+_b[after11]*after11+_b[after12]*after12+_b[after13]*after13+/*
*/_b[after14]*after14+_b[after15]*after15+_b[after16]*after16+_b[after17]*after17
bys country: egen cfmax`var'=max(cf`var')
gen tmp=cf`var'==cfmax`var'
gen tmp2=date*tmp
bys country: egen cfmaxdate`var'=max(tmp2)
format cfmaxdate`var' %d
drop tmp*
}
** Now we provide a graph with an example that shows how we arrived at the counterfactual peak
qui sum maxdateICUperinh if country=="Denmark"
local vertical1=r(mean)
qui sum cfmaxdateICUperinh if country=="Denmark"
local vertical2=r(mean)
local mindate=td(08mar2020)
local maxdate=td(28jun2020)
sort country date
twoway (line ICUperinh date if country=="Denmark" & sample) (line ICUperinh date if country=="Sweden" & sample, lpattern(dot)) (line cfICUperinh date if country=="Denmark"& sample, lpattern(dash)), yline(0, lcolor(black))/*
*/xline(`vertical1', lcolor(cyan)) xline(`vertical2', lcolor(cyan) lpattern(dash)) legend(order(1 "Denmark" 2 "Sweden" 3 "Denmark Counterfactual")) /*
*/xtitle("") ytitle("") scheme(s2mono) graphregion(margin(2 5 2 2)) xlabel(`mindate'(14)`maxdate', labsize(large) format(%tdddMon))
graph export "paper\figurepeak.png", replace
* Now we consider the difference in overall ICU-days between Norway/Denmark and counterfactual Norway/Denmark
bys id: egen ICUdays=sum(ICUperinh) if sample
bys id: egen cfICUdays=sum(cfICUperinh) if sample
**** Now we turn to hospitalizations. The major difference between hospitalizations and deaths/ICUs is that we do not have data before March 18th, which requires recoding of all the dummies
drop after* intd* intn* sample
* Set number of days that will be used for one dummy
local days=7
sum date
local maxdate=td(30jun2020)
local mindate=td(18mar2020)
* I is the number of x days-period between lockdown and the end of the sample
local I=ceil((`maxdate'-`mindate')/`days')
* Now create a dummy for each x-day period after the lockdown
forval i=1/`I' {
gen after`i'=0
gen tmp=td(18mar2020)+(`i'-1)*`days'
gen tmp2=td(18mar2020)+`i'*`days'
replace after`i'=1 if date>=tmp & date<tmp2
drop tmp*
}
* Interact the periods with the dummies for Norway and Denmark
forval i=1/`I' {
gen intdenmark`i'=after`i'*dummydenmark
gen intnorway`i'=after`i'*dummynorway
}
* We normalize the first dummy
drop after1 intdenmark1 intnorway1
gen sample=date>td(17mar2020) & date<td(01jul2020)
* Now run regressions
foreach var of varlist hospitalizedp {
* Run the event-study regression for each variable of interest
reg `var' after* intd* intn* dummyd dummyn if sample, vce(rob)
* Store the coefficients, the dates to which they belong and their 95-percent confidence interval in a matrix
mat coefficients=[_b[intdenmark2], _b[intdenmark2]-2*_se[intdenmark2], _b[intdenmark2]+2*_se[intdenmark2], _b[intnorway2], _b[intnorway2]-2*_se[intnorway2], _b[intnorway2]+2*_se[intnorway2] , td(27mar2020)]
mat coefficients=[0,0,0,0,0,0,td(20mar2020)]\coefficients  
forval i=3/`I' {
mat coefficients=coefficients \ [_b[intdenmark`i'],_b[intdenmark`i']-2*_se[intdenmark`i'],_b[intdenmark`i']+2*_se[intdenmark`i'],_b[intnorway`i'],_b[intnorway`i']-2* _se[intnorway`i'], _b[intnorway`i']+2* _se[intnorway`i'] , td(20mar2020)+7*(`i'-1)]
}
* Give names to the columns
matrix colnames coefficients= Denmark Denmark_lb Denmark_ub Norway Norway_lb Norway_ub date
* Preserve and clear the data
preserve
clear
* Use the matrix of coefficients as the data
svmat coefficients, names(col)
save coeffients`var', replace
* Save the mindate and maxdate as locals in Stata format
local mindate=td(08mar2020)
local maxdate=td(30jun2020)
local mindate2=td(06mar2020)
local vertical2=td(20apr2020)
twoway (line Denmark date, lcolor(red)) (line Norway date , lcolor(black)) (rcap Denmark_ub Denmark_lb date , lcolor(red)) (rcap Norway_ub Norway_lb date , lcolor(black))/*
*/, legend(order(1 "Denmark" 2 "Norway")) xtitle("") ytitle("") xline(`vertical', lcolor(cyan)) xline(`vertical2', lcolor(cyan) lpattern(dash)) yline(0, lcolor(black)) graphregion(margin(2 5 2 2)) legend(size(large)) ylabel(,labsize(large))/*
*/ xlabel(`mindate2'(14)`maxdate', labsize(large) format(%tdddMon))
graph export "paper\figure`var'.png", replace
restore
}
** And now calculate the peak data for hospitalizations
foreach var of varlist hospitalizedp {
* Find the actual maximum
bys country: egen max`var'=max(`var')
* Create a dummy which equals 1 on the date the variable attains its maximum
gen tmp=`var'==max`var'
gen tmp2=date*tmp
bys country: egen maxdate`var'=max(tmp2)
format maxdate`var' %d
drop tmp*
* Now generate the counterfactual values for Norway and Denmark
reg `var' after* intd* intn* dummyd dummyn if sample, vce(rob)
gen cf`var'=_b[_cons]+dummydenmark*_b[dummydenmark]+_b[dummynorway]*dummynorway+_b[after2]*after2+_b[after3]*after3+_b[after4]*after4+_b[after5]*after5+/*
*/_b[after6]*after6+_b[after7]*after7+_b[after8]*after8+_b[after9]*after9+_b[after10]*after10+_b[after11]*after11+_b[after12]*after12+_b[after13]*after13+/*
*/_b[after14]*after14+_b[after15]*after15
bys country: egen cfmax`var'=max(cf`var')
gen tmp=cf`var'==cfmax`var'
gen tmp2=date*tmp
bys country: egen cfmaxdate`var'=max(tmp2)
format cfmaxdate`var' %d
drop tmp*
}
bys id: egen hospitalizeddays=sum(hospitalizedp) if sample
bys id: egen cfhospitalizeddays=sum(cfhospitalizedp) if sample

xxxx

***** We do the whole thing again, but change the way we interpolate Sweden's IC cases
use "20200821FINAL.dta", clear
* Create country dummies
encode country, gen(id)
* Set panel
xtset id date
* For Sweden we interpolate intensive care patients between March 6-March 18 assuming linear growth
reg intensive_care date if date>td(5mar2020) & date<td(19mar2020) & country=="Sweden"
predict tmp
replace intensive_care=tmp if date>td(5mar2020) & date<td(19mar2020) & country=="Sweden"
drop tmp
*** Number of inhabitants for each country
gen inhabitants=0
replace inhabitants=5367580 if country=="Norway"
replace inhabitants=10327589 if country=="Sweden"
replace inhabitants=5827463 if country=="Denmark"
*** Normalize data on hospitalization and ICU for Denmark, Sweden and Norway to data per inhabitant
gen hospitalizedperinh=hospitalized/inh*1000000
gen ICUperinh=intensive_care/inh*1000000
gen deathsperinh=total_d/inh*1000000
* Create a dummy for Norway and Denmark
gen dummydenmark=0
replace dummydenmark=1 if country=="Denmark"
label var dummydenmark "Denmark Fixed Effect"
gen dummynorway=0
replace dummynorway=1 if country=="Norway"
label var dummynorway "Norway Fixed Effect"
* Now calculate the difference for each variable between Denmark/Norway and Sweden
sort date id
foreach var of varlist hospitalizedperinh ICUperinh deathsperinh {
by date: gen diffD`var'=`var'[1]-`var'[_N]
by date: gen diffN`var'=`var'[2]-`var'[_N]
}
label var date "date"
label var diffDh "Hospitalizations DK-SW"
label var diffDI "Denmark-Sweden"
label var diffDd "Deaths DK-SW"
label var diffNh "Hospitalizations NO-SW"
label var diffNI "Norway-Sweden"
label var diffNd "Deaths NO-SW"
* Set number of days that will be used for one dummy
local days=7
sum date
local maxdate=td(30jun2020)
local mindate=td(05mar2020)
* I is the number of x days-period between lockdown and the end of the sample
local I=ceil((`maxdate'-`mindate')/`days')
* Now create a dummy for each x-day period after the lockdown
forval i=1/`I' {
gen after`i'=0
gen tmp=td(05mar2020)+(`i'-1)*`days'
gen tmp2=td(05mar2020)+`i'*`days'
replace after`i'=1 if date>=tmp & date<tmp2
drop tmp*
}
* Interact the periods with the dummies for Norway and Denmark
forval i=1/`I' {
gen intdenmark`i'=after`i'*dummydenmark
gen intnorway`i'=after`i'*dummynorway
}
* Now we create an event-study
* Drop the variables for the second period which will serve as the omitted period in the regressions
drop after2 intdenmark2 intnorway2
gen sample=date>td(04mar2020) & date<td(01jul2020)
xtset id date
* Now run regressions
foreach var of varlist ICUperinh {
* Run the event-study regression for each variable of interest
reg `var' after* intd* intn* dummyd dummyn if sample, vce(rob)
* Store the coefficients, the dates to which they belong and their 95-percent confidence interval in a matrix
mat coefficients=[_b[intdenmark1], _b[intdenmark1]-2*_se[intdenmark1], _b[intdenmark1]+2*_se[intdenmark1], _b[intnorway1], _b[intnorway1]-2*_se[intnorway1], _b[intnorway1]+2*_se[intnorway1] , td(08mar2020)]
mat coefficients=coefficients \ [0,0,0,0,0,0,td(15mar2020)]
forval i=3/`I' {
mat coefficients=coefficients \ [_b[intdenmark`i'],_b[intdenmark`i']-2*_se[intdenmark`i'],_b[intdenmark`i']+2*_se[intdenmark`i'],_b[intnorway`i'],_b[intnorway`i']-2* _se[intnorway`i'], _b[intnorway`i']+2* _se[intnorway`i'] , td(08mar2020)+7*(`i'-1)]
}
* Give names to the columns
matrix colnames coefficients= Denmark Denmark_lb Denmark_ub Norway Norway_lb Norway_ub date
* Preserve and clear the data
preserve
clear
* Use the matrix of coefficients as the data
svmat coefficients, names(col)
save coeffients`var', replace
* Save the mindate and maxdate as locals in Stata format
local mindate=td(08mar2020)
local maxdate=td(30jun2020)
local vertical=td(11mar2020)
local vertical2=td(20apr2020)
twoway (line Denmark date, lcolor(red)) (line Norway date , lcolor(black)) (rcap Denmark_ub Denmark_lb date , lcolor(red)) (rcap Norway_ub Norway_lb date , lcolor(black))/*
*/, legend(order(1 "Denmark" 2 "Norway")) xtitle("") ytitle("") xline(`vertical', lcolor(cyan)) xline(`vertical2', lcolor(cyan) lpattern(dash)) yline(0, lcolor(black)) graphregion(margin(2 5 2 2)) legend(size(large)) ylabel(,labsize(large))/*
*/ xlabel(`mindate'(14)`maxdate', labsize(large) format(%tdddMon))
graph export "paper\figurelinear`var'.png", replace
restore
}
 

***** We do the whole thing again, but again change the way we interpolate Sweden's IC cases
use "20200821FINAL.dta", clear
* Create country dummies
encode country, gen(id)
* Set panel
xtset id date
* For Sweden we interpolate intensive care patients between March 6-March 18 using data on inflows and interpolating outflows
gen dintensive_care=D.intensive_care
gen outflowintensivecare=intensive_care_new-dintensive_care
reg outflowintensivecare L.intensive_care if country=="Sweden", nocons
replace intensive_care=(1-_b[L.intensive_care])*L.intensive_care+intensive_care_new if country=="Sweden" & date<td(18mar2020) & date>td(06mar2020)

*** Number of inhabitants for each country
gen inhabitants=0
replace inhabitants=5367580 if country=="Norway"
replace inhabitants=10327589 if country=="Sweden"
replace inhabitants=5827463 if country=="Denmark"
*** Normalize data on hospitalization and ICU for Denmark, Sweden and Norway to data per inhabitant
gen hospitalizedperinh=hospitalized/inh*1000000
gen ICUperinh=intensive_care/inh*1000000
gen deathsperinh=total_d/inh*1000000
* Create a dummy for Norway and Denmark
gen dummydenmark=0
replace dummydenmark=1 if country=="Denmark"
label var dummydenmark "Denmark Fixed Effect"
gen dummynorway=0
replace dummynorway=1 if country=="Norway"
label var dummynorway "Norway Fixed Effect"
* Now calculate the difference for each variable between Denmark/Norway and Sweden
sort date id
foreach var of varlist hospitalizedperinh ICUperinh deathsperinh {
by date: gen diffD`var'=`var'[1]-`var'[_N]
by date: gen diffN`var'=`var'[2]-`var'[_N]
}
label var date "date"
label var diffDh "Hospitalizations DK-SW"
label var diffDI "Denmark-Sweden"
label var diffDd "Deaths DK-SW"
label var diffNh "Hospitalizations NO-SW"
label var diffNI "Norway-Sweden"
label var diffNd "Deaths NO-SW"
* Set number of days that will be used for one dummy
local days=7
sum date
local maxdate=td(30jun2020)
local mindate=td(05mar2020)
* I is the number of x days-period between lockdown and the end of the sample
local I=ceil((`maxdate'-`mindate')/`days')
* Now create a dummy for each x-day period after the lockdown
forval i=1/`I' {
gen after`i'=0
gen tmp=td(05mar2020)+(`i'-1)*`days'
gen tmp2=td(05mar2020)+`i'*`days'
replace after`i'=1 if date>=tmp & date<tmp2
drop tmp*
}
* Interact the periods with the dummies for Norway and Denmark
forval i=1/`I' {
gen intdenmark`i'=after`i'*dummydenmark
gen intnorway`i'=after`i'*dummynorway
}
* Now we create an event-study
* Drop the variables for the second period which will serve as the omitted period in the regressions
drop after2 intdenmark2 intnorway2
gen sample=date>td(04mar2020) & date<td(01jul2020)
xtset id date
* Now run regressions
foreach var of varlist ICUperinh {
* Run the event-study regression for each variable of interest
reg `var' after* intd* intn* dummyd dummyn if sample, vce(rob)
* Store the coefficients, the dates to which they belong and their 95-percent confidence interval in a matrix
mat coefficients=[_b[intdenmark1], _b[intdenmark1]-2*_se[intdenmark1], _b[intdenmark1]+2*_se[intdenmark1], _b[intnorway1], _b[intnorway1]-2*_se[intnorway1], _b[intnorway1]+2*_se[intnorway1] , td(08mar2020)]
mat coefficients=coefficients \ [0,0,0,0,0,0,td(15mar2020)]
forval i=3/`I' {
mat coefficients=coefficients \ [_b[intdenmark`i'],_b[intdenmark`i']-2*_se[intdenmark`i'],_b[intdenmark`i']+2*_se[intdenmark`i'],_b[intnorway`i'],_b[intnorway`i']-2* _se[intnorway`i'], _b[intnorway`i']+2* _se[intnorway`i'] , td(08mar2020)+7*(`i'-1)]
}
* Give names to the columns
matrix colnames coefficients= Denmark Denmark_lb Denmark_ub Norway Norway_lb Norway_ub date
* Preserve and clear the data
preserve
clear
* Use the matrix of coefficients as the data
svmat coefficients, names(col)
save coeffients`var', replace
* Save the mindate and maxdate as locals in Stata format
local mindate=td(08mar2020)
local maxdate=td(30jun2020)
local vertical=td(11mar2020)
local vertical2=td(20apr2020)
twoway (line Denmark date, lcolor(red)) (line Norway date , lcolor(black)) (rcap Denmark_ub Denmark_lb date , lcolor(red)) (rcap Norway_ub Norway_lb date , lcolor(black))/*
*/, legend(order(1 "Denmark" 2 "Norway")) xtitle("") ytitle("") xline(`vertical', lcolor(cyan)) xline(`vertical2', lcolor(cyan) lpattern(dash)) yline(0, lcolor(black)) graphregion(margin(2 5 2 2)) legend(size(large)) ylabel(,labsize(large))/*
*/ xlabel(`mindate'(14)`maxdate', labsize(large) format(%tdddMon))
graph export "paper\figureinflow`var'.png", replace
restore
}
 

















































